package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.GalleryPicDetailActivity;
import com.fancy.learncenter.activity.YgtDetailDecActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.YgtGallaryDataBean;
import com.fancy.learncenter.utils.ToastUtil;
import com.superservice.lya.R;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by hyy on 2018/1/27.
 * Explain activity as
 */

public class YgtPicAdapter extends CommonRecycleViewAdapter<YgtGallaryDataBean> {
    private boolean isEdit = false;

    public YgtPicAdapter(Context mContext, ArrayList<YgtGallaryDataBean> itemDatas) {
        super(mContext, R.layout.pic_item, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final YgtGallaryDataBean item, final int position) {

        SimpleDraweeView pic = customViewHold.getView(R.id.pic);

        pic.setImageURI(item.getThumbsrc());

        final ImageView status = customViewHold.getView(R.id.status);


        if (isEdit) {

            if (item.getIs_sys() == 1) {
                status.setVisibility(View.GONE);
            } else {
                status.setVisibility(View.VISIBLE);
            }


            if (item.getImg_status() == 0) {
//            status.setVisibility(View.GONE);
                status.setImageResource(R.mipmap.bg_moren);
            } else {
//            status.setVisibility(View.VISIBLE);
                status.setImageResource(R.mipmap.bg_xuanzhong);
            }

            pic.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (item.getIs_sys() == 1) {
                        ToastUtil.show("系统图集不可删除");
                    } else {
                        if (item.getImg_status() == 0) {
//            status.setVisibility(View.GONE);
                            item.setImg_status(1);
                        } else {
//            status.setVisibility(View.VISIBLE);

                            item.setImg_status(0);
                        }
                        notifyItemChanged(position);
                    }

                }
            });

        } else {
            status.setVisibility(View.GONE);


            pic.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ArrayList<String> detailPicData = new ArrayList<>();
                    for (int i = 0; i < itemDatas.size(); i++) {
                        detailPicData.add(itemDatas.get(i).getImgsrc());
                    }
                    Intent intent = new Intent(mContext, GalleryPicDetailActivity.class);
                    intent.putExtra(GalleryPicDetailActivity.PIC_KEY, detailPicData);
                    intent.putExtra(GalleryPicDetailActivity.PIC_POSITION_KEY, position);
                    mContext.startActivity(intent);
                }

            });
        }

    }

    private CallBack callBack;

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    public interface CallBack {
        abstract void OnClick();

    }

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }
}



